package com.example.administrator.yuejian2.model;

import com.example.administrator.yuejian2.RetrofitListener.RetrofitListener;
import com.example.administrator.yuejian2.bean.QuestionBean;
import com.example.administrator.yuejian2.service.QuestionService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.example.administrator.yuejian2.other.Url.BASEURL;
import static com.example.administrator.yuejian2.other.Url.URL1;
import static com.example.administrator.yuejian2.other.Url.URL3;

public class QuestionModel {
    private Retrofit retrofit;
    private QuestionService questionService;


    public QuestionModel ()
    {
        retrofit=new Retrofit.Builder()
                .baseUrl(BASEURL+URL3)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        questionService=retrofit.create(QuestionService.class);
    }
    public void getQuestionList(String user_id,final RetrofitListener listener)
    {
        Call<List<QuestionBean>> call=questionService.getQuestionList(user_id);
        call.enqueue(new Callback<List<QuestionBean>>() {
            @Override
            public void onResponse(Call<List<QuestionBean>> call, Response<List<QuestionBean>> response) {
                listener.onSuccess(response.body(),1);
            }

            @Override
            public void onFailure(Call<List<QuestionBean>> call, Throwable t) {
                listener.onFail();
            }
        });
    }
}
